# -*- coding: utf-8 -*-


"""
装饰模式

模式特点：动态地为对象增加额外的职责

程序实例：展示一个人一件一件穿衣服的过程。

代码特点：无
"""


class Person(object):
    def __init__(self, name):
        self.name = name

    def show(self):
        print "dressed {}".format(self.name)


class Finery(Person):
    component = None

    def __init__(self):
        pass

    def decorate(self, ct):
        self.component = ct

    def show(self):
        if self.component:
            self.component.show()


class TShirts(Finery):
    def __init__(self):
        pass

    def show(self):
        print "Big T-shirt"
        self.component.show()


class BigTrouser(Finery):
    def __init__(self):
        pass

    def show(self):
        print "Big Trouser"
        self.component.show()


if __name__ == "__main__":
    p = Person("somebody")
    bt = BigTrouser()
    ts = TShirts()
    bt.decorate(p)
    ts.decorate(bt)
    ts.show()
